package com.trendytech.tds.message.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.trendytech.tds.entity.SystemThresholdEntity;
import com.trendytech.tds.message.dao.ISystemThresholdDAO;

import hm.base.dao.impl.AbstractDAO;

@Repository
public class SystemThresholdDAOImpl extends AbstractDAO<SystemThresholdEntity> implements ISystemThresholdDAO {

	private static final String MAPPER_SELECT_VALUE_BY_TYPE_AND_CREATOR = "selectValueByTypeAndCreator";
	private static final String MAPPER_SELECT_VALUE_BY_TYPE = "selectValueByType";
	private static final String MAPPER_SELECT_VALUE_BY_CREATOR = "selectValueByCreator";
	private static final String MAPPER_DELETE_ALL = "deleteAll";
	private static final String MAPPER_DELETE_BY_CREATOR = "deleteByCreator";
	private static final String MAPPER_DELETE_BY_TYPE_AND_CREATOR = "deleteByTypeAndCreator"; 
	private static final String MAPPER_DELETE_BY_TYPE = "deleteByType"; 
//	private static final String MAPPER_SELECT_ALL = "selectThreshold";
	private static final String MAPPER_SELECT_ALL = "selectThresholds";
	private static final String MAPPER_SELECT_VALUE_BY_ID = "selectValueById";
	private static final String MAPPER_UPDATE_VALUE_BY_ENTITY = "updateByEntity";
	private static final String MAPPER_UPDATE_Hole_Entity = "updateHoleEntity";
	private static final String MAPPER_INSERT_VALUE_BY_ENTITY = "insertByEntity";
	private static final String MAPPER_SELECT_IMPORTANCE = "selectImpByType";
	@Override
	public List<SystemThresholdEntity> getSystemThresholdByType(int type) {
		return sqlSession.selectList(MAPPER_SELECT_VALUE_BY_TYPE, type);
	}

	@Override
	public SystemThresholdEntity getSystemThresholdByTypeAndCreator(SystemThresholdEntity entity) {
		return sqlSession.selectOne(MAPPER_SELECT_VALUE_BY_TYPE_AND_CREATOR, entity);
	}

	@Override
	public int deleteAll() {
		return sqlSession.delete(MAPPER_DELETE_ALL);
	}

	@Override
	public int deleteByCreator(String creator) {
		return sqlSession.delete(MAPPER_DELETE_BY_CREATOR, creator);
	}

	@Override
	public int deleteByTypeAndCreator(SystemThresholdEntity entity) {
		return sqlSession.delete(MAPPER_DELETE_BY_TYPE_AND_CREATOR, entity);
	}
	
	@Override
	public int deleteByType(SystemThresholdEntity entity) {
		return sqlSession.delete(MAPPER_DELETE_BY_TYPE, entity);
	}

	@Override
	public List<SystemThresholdEntity> getSystemThresholdByCreator(String creator) {
		return sqlSession.selectList(MAPPER_SELECT_VALUE_BY_CREATOR, creator);
	}

	@Override
	public List<SystemThresholdEntity> getSystemThreshold() {
		return sqlSession.selectList(MAPPER_SELECT_ALL);
	}

	@Override
	public SystemThresholdEntity getSystemThresholdById(String id) {
		return sqlSession.selectOne(MAPPER_SELECT_VALUE_BY_ID, id);
	}

	@Override
	public int updateThresholdByEntity(SystemThresholdEntity entity) {
		// TODO Auto-generated method stub
		return sqlSession.update(MAPPER_UPDATE_VALUE_BY_ENTITY, entity);
	}

	@Override
	public int updateByEntity(SystemThresholdEntity entity) {
		// TODO Auto-generated method stub
		return sqlSession.update(MAPPER_UPDATE_Hole_Entity, entity);
	}
	
	@Override
	public int insertThreshold(SystemThresholdEntity entity) {
		// TODO Auto-generated method stub
		return sqlSession.insert(MAPPER_INSERT_VALUE_BY_ENTITY, entity);
	}

	@Override
	public int getImportance(int type) {
		Map<String, Integer> map = new HashMap<String, Integer>();
		map.put("type", type);
		return sqlSession.selectOne(getMapperId(MAPPER_SELECT_IMPORTANCE), map);
	}

}
